import remoteBrand from './remote_brand.js';
import remoteShop from './remote_shop.js'
//原型
let a = [
  {text: '路特斯', brand: '路特斯', id: 'k0'},
  {text: '领 克', brand: '领克', id: 'k1'},
  {text: '大众ID', brand: '大众ID', id: 'k2'},
  {text: '哪 吒', brand: '哪吒', id: 'k3'},
  {text: '一汽奥迪', brand: '奥迪', id: 'k5'},
  {text: '宝 马', brand: 'BMW', id: 'k6'},
  {text: '林 肯', brand: '林肯', id: 'k7'},
  {text: '沃尔沃', brand: '沃尔沃', id: 'k8'},
  {text: '阿维塔', brand: '阿维塔', id: 'k4'},
  {text: '迷 你', brand: 'MINI', id: 'k9'},
  {text: '进口大众', brand: '进口大众', id: 'k10'},
  {text: '上汽大众', brand: '上汽大众', id: 'k11'},
  {text: '一汽大众', brand: '一汽大众', id: 'k12'},
  {text: '吉 普', brand: 'JEEP', id: 'k13'},
  {text: '斯巴鲁', brand: '斯巴鲁', id: 'k14'},
  {text: '福特纵横', brand: '福特纵横', id: 'k15'},
  {text: '长安福特', brand: '长安福特', id: 'k16'},
  {text: '广汽丰田', brand: '广汽丰田', id: 'k17'},
  {text: '东风本田', brand: '东风本田', id: 'k18'},
  {text: '北京现代', brand: '北京现代', id: 'k19'},
  {text: '腾 势', brand: '腾势', id: 'k20'},
];

//组合
let c = [
  {em: '1', text: '路特斯', brand: '路特斯', id: 'k0'},
  {em: '1', text: '腾 势', brand: '腾势', id: 'k20'},
  {em: '1', text: '领 克', brand: '领克', id: 'k1'},
  {em: '1', text: '大众ID', brand: '大众ID', id: 'k2'},
  {em: '1', text: '哪 吒', brand: '哪吒', id: 'k3'},
  {em: '0', text: '一汽奥迪', brand: '奥迪', id: 'k5'},
  {em: '0', text: '宝马/迷你', brand :['BMW','MINI'], id: 'k6'},
  {em: '0', text: '林 肯', brand: '林肯', id: 'k7'},
  {em: '0', text: '沃尔沃', brand: '沃尔沃', id: 'k8'},
  {em: '1', text: '阿维塔', brand: '阿维塔', id: 'k4'},
  //{em: '0', text: '迷 你', brand: 'MINI', id: 'k9'},
  {em: '0', text: '进口大众', brand: '进口大众', id: 'k10'},
  {em: '0', text: '上汽大众', brand: '上汽大众', id: 'k11'},
  {em: '0', text: '一汽大众', brand: '一汽大众', id: 'k12'},
  {em: '0', text: '吉 普', brand: 'JEEP', id: 'k13'},
  {em: '0', text: '斯巴鲁', brand: '斯巴鲁', id: 'k14'},
  {em: '0', text: '福特纵横', brand: '福特纵横', id: 'k15'},
  {em: '0', text: '长安福特', brand: '长安福特', id: 'k16'},
  {em: '0', text: '广汽丰田', brand: '广汽丰田', id: 'k17'},
  {em: '0', text: '东风本田', brand: '东风本田', id: 'k18'},
  {em: '0', text: '北京现代', brand: '北京现代', id: 'k19'},
];

//原型店铺
let b = [
  {
    brand:'腾势',
    id: 'k0',
    child: [
      {department: '苏州腾运（尹山汽车城）'},
    ],
  },
  {
    brand: '路特斯',
    id: 'k0',
    child: [
      {department: '常州路卡斯（武进汽车城）'},
      {department: '南通路卡斯（东方汽车城）'},
    ],
  },
  {
    brand: '领克',
    id: 'k1',
    child: [
      {department: '常州领创（武进汽车城）'},
      {department: '溧阳领畅（昆仑汽车城）'},
    ],
  },
  {
    brand: '大众ID',
    id: 'k2',
    child: [
      {department: '常州众成（武进汽车城）',alaisName : '常州众成（上汽大众•武进汽车城）',brandId:13},
      {department: '常州众恒（钟楼汽车城）',alaisName : '常州众恒（上汽大众•钟楼汽车城）',brandId:13},
      {department: '常州宝达（武进汽车城）',alaisName : '常州宝达（一汽大众•武进汽车城）',brandId:12},
      {department: '苏州德诚（尹山汽车城）',alaisName : '苏州德诚（一汽大众•尹山汽车城）',brandId:12},
    ],
  },
  {brand: '哪吒', id: 'k3', child: [{department: '常州苏诺（武进汽车城）'}]},
  {brand: '阿维塔', id: 'k4', child: [{department: '无锡富绅（锡西汽车城）'}]},
  {
    brand: '奥迪',
    id: 'k5',
    child: [
      {department: '常州新奥（武进汽车城）'},
      {department: '常州凯歌（环球港对面）'},
      {department: '金坛新奥（新汽车城）'},
      {department: '溧阳凯歌（昆仑汽车城）'},
    ],
  },
  {
    brand: 'BMW',
    id: 'k6',
    child: [
      {department: '扬州宝华（江都汽车城）',alaisName:'扬州宝华（宝马•江都汽车城）'},
      {department: '高邮宝华（城南汽车城）',alaisName:'高邮宝华（宝马•城南汽车城）'},
    ],
  },
  {
    brand: '林肯',
    id: 'k7',
    child: [
      {department: '常州肯特（武进汽车城）'},
      {department: '钟楼肯特（钟楼汽车城）'},
      {department: '溧阳肯特（昆仑汽车城）'},
      {department: '南通肯特（东方汽车城）'},
      {department: '苏州肯特（尹山汽车城）'},
      {department: '昆山肯特（周市汽车城）'},
    ],
  },
  {
    brand: '沃尔沃',
    id: 'k8',
    child: [
      {department: '常州富豪（武进汽车城）'},
      {department: '常州富尊（城北丽亭酒店旁）'},
      {department: '溧阳富豪（昆仑汽车城）'},
      {department: '扬州富豪（城北汽车城）'},
    ],
  },
  {brand: 'MINI', id: 'k9', child: [{department: '扬州宝华（江都汽车城）',alaisName:'扬州宝华（MINI•江都汽车城）'}]},
  {                                                                                                
    brand: '进口大众',                                                                             
    id: 'k10',                                                                                     
    child: [{department: '常州德立（武进汽车城）'}],
  },
  {
    brand: '上汽大众',
    id: 'k11',
    child: [
      {department: '常州众成（武进汽车城）'},
      {department: '常州众恒（钟楼汽车城）'},
    ],
  },
  {
    brand: '一汽大众',
    id: 'k12',
    child: [
      {department: '常州宝达（武进汽车城）'},
      {department: '金坛宝达（新汽车城）'},
      {department: '溧阳宝达（昆仑汽车城）'},
      {department: '苏州德诚（尹山汽车城）'},
    ],
  },
  {brand: 'JEEP', id: 'k13', child: [{department: '常州君爵（武进汽车城）'}]},
  {
    brand: '斯巴鲁',
    id: 'k14',
    child: [{department: '常州斯巴鲁（武进汽车城）'}],
  },
  {
    brand: '福特纵横',
    id: 'k15',
    child: [
      {department: '常州汇福（武进汽车城）'},
      {department: '南通聚福（东方汽车城）'},
    ],
  },
  {
    brand: '长安福特',
    id: 'k16',
    child: [{department: '常州福特（武进汽车城）'}],
  },
  {
    brand: '广汽丰田',
    id: 'k17',
    child: [{department: '常州威宇（武进汽车城）'}],
  },
  {
    brand: '东风本田',
    id: 'k18',
    child: [{department: '常州东昇（环球港对面）'}],
  },
  {
    brand: '北京现代',
    id: 'k19',
    child: [{department: '常州明盛（武进汽车城）'}],
  },
];


let errShops = [];
//查找店铺id
b.forEach(res => {
  res.child.forEach(dep => {
    let shop = remoteShop.data.find(res => res.name == dep.department);
    if(shop){
      //店铺的id查找
      //console.log(shop)
      dep.rid = shop.id;
      //dep.bid = shop.bid;
    }else{
      errShops.push(dep.department);
      console.log(`未找到店铺`,dep);
    }
  })
});
console.log(errShops);
let list = a.map(res => {
  let { brand } = res;
  let remoteBrandItem = remoteBrand.data.find(item => item.name == brand);
  let brandId,department;
  if(!remoteBrandItem){
    //这时候查看是否有店铺数据
    department = b.find(res => res.brand == brand);
    if(department){
      department.child.forEach(res => {
        res.brandName = brand;
      });
    }else{
      console.log(`不存在`,res);
    }
  }else{
    brandId = remoteBrandItem.id;
    department = b.find(res => res.brand == brand);
    department.child.forEach(res => {
      res.brandId = brandId;
      res.brandName = brand;
    });
  }
  //console.log(departments);
  res.department = department && department.child || [];
  return res;
});

let showList = c.map(res => {
  let departments = [];
  let { brand } = res;
  if(!Array.isArray(brand)){
    brand = [brand];
  }else{
    brand
  }
  brand.forEach(brandOne => {
    let item = list.find(res => res.brand == brandOne);
    departments = departments.concat(item.department);
  });
  res.department = departments;
  return res;
});
export default list;
export {showList}
